
ALTER PROCEDURE [dbo].[GetNextPlayer] 
	@Game_ID numeric(10,0) = null
AS
BEGIN 

	Declare @prevPlayer numeric(10,0)
	Declare @currentPlayer numeric(10,0)
	
	set @prevPlayer = (select sequenceno from  dbo.PlayerEnrollment where isMyMove = 'Y')
	PRINT N'This user has SET NOCOUNT turned ON.';
	
	set @currentPlayer =
		(select TOP 1 sequenceno
		from dbo.PlayerEnrollment
		where isActive = 'Y'
		and sequenceno > 0
		and sequenceno > @prevPlayer
		and isMyMove = 'N'
		order by 1)
	
	IF @currentPlayer = NULL
	BEGIN
		print 'a'
		set @currentPlayer =
		(select TOP 1 sequenceno
		from dbo.PlayerEnrollment
		where isActive = 'Y'
		and sequenceno > 0
		and sequenceno < @prevPlayer
		and isMyMove = 'N'
		order by 1)
	END
	
	select @currentPlayer 

END

-- [dbo].[GetNextPlayer]  1